Mapping castles in France

Using R

Lidiya Mishieva ORCID

Department of Methodology and Statistics, Utrecht University

2025-10-20

Intro

  • Open Street Maps (OSM) can be a great data source
  • In this presentation, we will see how to extract and use this data to map castles in France using R
  • For extracting, we will use the package ‘osmextract’
  • The function ‘oe_get()’ downloads a mirror of the OSM data base as specified by the user
  • Then, queries are performed locally using SQL
  • We use ‘tidyverse’ and ‘sf’ for operational procedures such as (spatial) data wrangling etc

Downloading the data

# load packages
library(tidyverse)
library(sf)
library(osmextract)

# wait 1000 seconds for the internet operation to complete
options(timeout = 1000)

# retrieve a data extract from a provider
castles <- oe_get(
  # define a geographical area to be matched with a .osm.pbf file
  place = "France",
  # define a provider
  provider = "geofabrik",
  # query the database locally (!) from a downloaded odm extract
  # only layer is filtered before downloading the extract
  query = "
    SELECT * FROM multipolygons
    WHERE historic = 'castle'
  ",
  # specify additional columns corresponding to OSM tags
  extra_tags = c("castle_type"),
  # define directory for the osm extract 
  download_directory = getwd(),
  # no messages
  quiet = TRUE
)

Let’s take a look at the data

Mapping the castles

Neither disjoint nor exhaustive selection of castle types in France …

Is the North really less defensive? Didn’t seem to bother the Normans.

Placeholder

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

No castle stands alone

We could think of defensiveness as determined by both regional and local influences. While regional factors (\(X\beta\)) capture site-specific conditions, the spatial lag term (\(\rho WY\)) reflects local interdependence, maybe because neighboring rulers responded to each other’s fortifications.

If the reduced form of the formula of the spatially-lagged Y model is written out and transformed, it becomes clear that due to the correlation of the error terms with \(Y\), the spatial lag must be treated as an endogenous (and not as an independent) variable (see Anselin (1988)):

\[\begin{equation} \begin{split} Y & = \rho WY + X\beta + \epsilon \\ Y-\rho WY & = X\beta + \epsilon \\ (I-\rho W)Y & = X\beta + \epsilon \\ Y & = (I − \rho W)^{−1}X\beta + (I − \rho W)^{−1}\epsilon. \end{split} \end{equation}\]

References and bibliography

Anselin, Luc. 1988. Spatial Econometrics: Methods and Models. Dordrecht: Kluwer Academic. https://doi.org/10.1007/978-94-015-7799-1.
Beech, George. 2005. Was the Bayeux Tapestry Made in France? Palgrave Macmillan US. https://doi.org/10.1007/978-1-137-07391-4.
Gilardi, Andrea, and Robin Lovelace. 2021. “Osmextract: Download and Import Open Street Map Data Extracts.” The R Foundation. https://doi.org/10.32614/cran.package.osmextract.
Marshall, Pamela. 2016. “Some Thoughts on the Use of the Anglo-Norman Donjon.” In, 159–74. Oxbow Books. https://doi.org/10.2307/j.ctt1kw2b5s.18.